package com.huaxindata.im.model.entity;

import com.baidu.mapapi.model.LatLng;

/**
 * @author songxf
 * @date 2018/1/8
 * @Desc $desc$
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class ChatLocationMessageBody extends ChatMessageBody {


    public LatLng latlng;
    //对应表中address
    public String addrInfo;
    public String tos;

    public ChatLocationMessageBody(int type) {
        super(type);
    }

    public ChatLocationMessageBody(double latitude, double latitude1, String locationAddress) {
        super(Type.LOCATION);
        this.latlng = new LatLng(latitude, latitude1);
        this.addrInfo = locationAddress;
    }


    /**
     * 根据message解析具体位置信息
     *
     * @param message
     */
    public void parseLocationMessage(String message) {
        //发送格式：latlng.latitude + "#" + latlng.longitude + "#" + addrInfo
        if (message == null) {
            throw new RuntimeException("Invalid type of this message :" + this);
        }
        if (latlng == null || addrInfo == null) {
            String[] infos = message.split(ChatMessage.PREX_LOCATION);
            try {
                latlng = new LatLng(Double.parseDouble(infos[0]), Double.parseDouble(infos[1]));
                addrInfo = infos[2];
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 拼接位置消息字符串
     *
     * @return
     */
    public String matchLocationMessage() {
        return latlng.latitude + ChatMessage.PREX_LOCATION + latlng.longitude + ChatMessage.PREX_LOCATION + addrInfo;
    }


    @Override
    public String toString() {
        return "ChatLocationMessageBody{" +
                "latlng=" + latlng +
                ", addrInfo='" + addrInfo + '\'' +
                ", tos='" + tos + '\'' +
                '}';
    }
}
